<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/10/29
 * Time: 下午8:20
1所有用户等级流失    
 每天占比=当天该等级人数/创角总人数   tblGameALLLevel / tblGameRole.CumRoleUser
 
2新用户等级流失    
 每天占比=当天新用户该等级人数/当天新创角总人数 tblGameNAULevel/ tblGameRole.RoleUser

3活跃用户等级流失    
 每天占比=活跃用户该等级人数/当天登录总人数   tblGameActiveLevel / tblGameLogin.LoginUser
            
 */

class WastageController extends AdminBaseController {

	
	public function allUserGrade(){
		$this->setTitle('所有用户等级流失');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();
	
		$lod_special_id = $this->R('special_id');
		$lodos = $this->R('os');
		$filter->addSpecialFilter(false,2);
		$filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2)
		->addFilter('time_start', 'input', '时间', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
		->addFilter('time_end', 'input', '至', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2);
	
		$params = $filter->get();
		
		$params = $this->indexCommon($params);

		$header = WastageService::gradeHeader($params,1);
		$data   = WastageService::gradeData($params,1);
	
		if($filter->isExport()){
			$filename = LibExcel::getFilename('所有用户等级流失', $params);
			LibExcel::exportCsv($header, $data, $filename);
		}else{
			$grid->addGrid($header, $data, array(
					'name'  => '所有用户等级流失',
					'order' => array('RecDate', 'desc'),
					'fix'   => array(
							'col' => 1
					)
			));
	
			$this->out['filter'] = $filter->show();
			$this->out['grid'] = $grid->show();
			$this->out['is_ana'] = 2;
		}
	}
	
	public function newUserGrade(){
		$this->setTitle('新用户等级流失');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();
	
		$lod_special_id = $this->R('special_id');
		$lodos = $this->R('os');
		$filter->addSpecialFilter(false,2);
		$filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2)
		->addFilter('time_start', 'input', '时间', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
		->addFilter('time_end', 'input', '至', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2);	
	
		$params = $filter->get();
		
		$params = $this->indexCommon($params);
	
		$header = WastageService::gradeHeader($params,2);
		$data   = WastageService::gradeData($params,2);
	
		if($filter->isExport()){
			$filename = LibExcel::getFilename('新用户等级流失', $params);
			LibExcel::exportCsv($header, $data, $filename);
		}else{
			$grid->addGrid($header, $data, array(
					'name'  => '新用户等级流失',
					'order' => array('RecDate', 'desc'),
					'fix'   => array(
							'col' => 1
					)
			));
	
			$this->out['filter'] = $filter->show();
			$this->out['grid'] = $grid->show();
			$this->out['is_ana'] = 2;
		}
	}
	
	public function activeUserGrade(){
		$this->setTitle('活跃用户等级流失');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();
	
		$lod_special_id = $this->R('special_id');
		$lodos = $this->R('os');
		$filter->addSpecialFilter(false,2);
		$filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2)
		->addFilter('time_start', 'input', '时间', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
		->addFilter('time_end', 'input', '至', array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2);
	
	
		$params = $filter->get();
		
		$params = $this->indexCommon($params);
		
		$header = WastageService::gradeHeader($params,3);		
		$data   = WastageService::gradeData($params,3);
	
		if($filter->isExport()){
			$filename = LibExcel::getFilename('活跃用户等级流失', $params);
			LibExcel::exportCsv($header, $data, $filename);
		}else{
			$grid->addGrid($header, $data, array(
					'name'  => '活跃用户等级流失',
					'order' => array('RecDate', 'desc'),
					'fix'   => array(
							'col' => 1
					)
			));
	
			$this->out['filter'] = $filter->show();
			$this->out['grid'] = $grid->show();
			$this->out['is_ana'] = 2;
		}
	}
    
    

    

    
} 